package com.yswy.common.model;

import com.yswy.common.enums.ResultStatus;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 自定义返回结果
 *
 * @author shihan
 */
@Getter
@Setter
public class ResultModel implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 返回码
     */
    private int code;
    /**
     * 返回结果描述
     */
    private String message;
    /**
     * 返回数据量
     */
    private Long count;
    /**
     * 返回内容
     */
    private Object data;

    public ResultModel() {

    }

    public ResultModel(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = "";
    }

    public ResultModel(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultModel(ResultStatus status, Object data) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.data = data;
    }

    public ResultModel(ResultStatus status, String message) {
        this.code = status.getCode();
        this.message = message;
    }

    public ResultModel(ResultStatus status) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.data = "";
    }

    public ResultModel(ResultStatus status, Object data, Long count) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.data = data;
        this.count = count;
    }




    public static ResultModel ok(Object content, Long count) {
        return new ResultModel(ResultStatus.SUCCESS, content, count);
    }

    public static ResultModel ok() {
        return new ResultModel(ResultStatus.SUCCESS);
    }


    public static ResultModel ok(Object content) {
        return new ResultModel(ResultStatus.SUCCESS, content);
    }

    public static ResultModel error(ResultStatus error) {
        return new ResultModel(error);
    }

    public static ResultModel error(String message) {
        return new ResultModel(-100, message);
    }


}
